package com.xyy.saas.payment.cores.vo;

import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author wangtianqi
 */
@Getter
@Setter
public class QueryFuminRecordBo implements Serializable {
    private static final long serialVersionUID = -6907333172448341887L;

    private int totalSize;

    private int pageNo;

    private List<FuminRecordBo> records;

    /**
     * 构建对象
     */
    public static QueryFuminRecordBo build(Map<String, Object> result) {
        if(result == null) {
            return null;
        }

        QueryFuminRecordBo queryFuminRecordBo = new QueryFuminRecordBo();
        queryFuminRecordBo.setTotalSize(Integer.parseInt((String) result.get("totalRows")));
        queryFuminRecordBo.setPageNo(Integer.parseInt((String) result.get("pageNo")));

        List<FuminRecordBo> records = new ArrayList<>();
        List<Map<String, String>> items = (List<Map<String, String>>) result.get("balanceRecords");

        if(items != null) {
            for(Map<String, String> item : items) {
                records.add(FuminRecordBo.build(item));
            }
        }

        queryFuminRecordBo.setRecords(records);
        return queryFuminRecordBo;
    }
}
